package temp;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class CsvRowCountReducer extends Reducer<NullWritable, LongWritable, NullWritable, LongWritable> {
    private LongWritable result = new LongWritable();

    @Override
    protected void reduce(NullWritable key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        long sum = 0;
        for (LongWritable value : values) {
            sum += value.get(); // 累加 LongWritable 类型的值
        }
        result.set(sum);
        context.write(NullWritable.get(), result); // 输出 LongWritable
    }
}